import Vue from 'vue'
import VueRouter, { Route } from 'vue-router'

import Home from '../pages/Home.vue'
import Goods from '../pages/Goods.vue'
import Detail from '../pages/Home.vue'
import User from '../pages/User.vue'
import NoPage from '../pages/NoPage.vue'

Vue.use(VueRouter); // 安装插件

let routes = [
    {path: '/home', component: Home},
    {path: '/goods', component: Goods},
    {path: '/detail', component: Detail},
    {path: '/user', component: User},
    // {
    //     path: '/user', 
    //     component: User,
    //     beforeEnter: (to:Route, from:Route, next:Function)=>{
    //         console.log('独享前置守卫')
    //     }
    // },
    {path: '/login', component: (r:any)=>{require(['../pages/Login.vue'], r)}},
    {path: '/reg', component: ()=>import('../pages/Reg.vue')},
    {path: '/', redirect: '/home'},
    {path: '*', component: NoPage},
]

let router = new VueRouter({
    mode: 'history',
    routes: routes
})
/*
// 全局守卫
router.beforeEach((to, from, next)=>{
    console.log('全局前置守卫')
    next()
})
router.afterEach((to, from)=>{
    console.log('全局后置守卫')
})
*/
export default router;